package com.naizhuai.ui.task.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.ui.entity.QuestionListBean;
import com.naizhuai.ui.entity.mainbusiness.ActionBaseBean;
import com.naizhuai.ui.mianbusiness.action.ActionBrightSpotActivity;
import com.naizhuai.ui.task.ActionSetting1Activity;
import com.naizhuai.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.subjects.PublishSubject;

/**
 * @author：lichenxi
 * @date 2018/3/13 16
 * email：525603977@qq.com
 * Fighting
 */
public class ActionAdapter extends RecyclerView.Adapter<ActionAdapter.ViewHolder> {

    private List<QuestionListBean> mTaskLinks;
    private PublishSubject<String> mSubject=PublishSubject.create();
    private CallBackQuestion mCallBackQuestion;
    public ActionAdapter(CallBackQuestion callBackQuestion) {
        this.mCallBackQuestion=callBackQuestion;
    }

    public void setActionData(List<QuestionListBean> taskLinks) {
        mTaskLinks = taskLinks;
        notifyDataSetChanged();
    }


    public PublishSubject<String> getClickAction() {
        return mSubject;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.step_action, parent, false);
        return new ViewHolder(root);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        QuestionListBean questionBean = mTaskLinks.get(position);
        ViewUtils.showRoundImg(questionBean.questionImg,holder.imageView);
        holder.actionName.setText(questionBean.questionName);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBackQuestion.onClickAction(questionBean.questionId);

            }
        });
//        holder.timeline.setText(TimeUtils.dateString(questionBean.getStartTime()));
//        Glide.with(context).load(questionBean.getQuestionImg()).into(holder.imageView);
//        Glide.with(context).load(questionBean.getPublisherThumb()).into(holder.userimg);
//        holder.username.setText(questionBean.getPublisherName());
    }

    @Override
    public int getItemCount() {
        return mTaskLinks!=null?mTaskLinks.size():0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.imageView)
        ImageView imageView;
        @BindView(R.id.actionName)
        TextView actionName;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
   public interface CallBackQuestion {
        void onClickAction(String questionid);
   }
}
